﻿// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Inrerface/TakeInterface.h"
#include "Components/TimelineComponent.h"
#include "Plant.generated.h"

class UBoxComponent;
class USkeletalMesh;
class UAnimationAsset;
class USkeletalMeshComponent;
class UMeshComponent;

/**
 *  植物
 */

UCLASS()
class GROWTHDEPENDENT_API APlant : public AActor, public ITakeInterface
{
	GENERATED_BODY()

public:
	APlant();

	// 植物大小
	UPROPERTY(BlueprintReadWrite, EditAnywhere, meta=(ExposeOnSpawn = "true"), DisplayName="生长后的大小", Category="默认|生长相关")
	FVector PlantMeshSize = FVector(1.f, 1.f, 1.f);

	// 初始大小
	UPROPERTY(BlueprintReadWrite, EditAnywhere, meta=(ExposeOnSpawn = "true"), DisplayName="初始大小", Category="默认|生长相关")
	float PlantMeshInitSize = 0.25f;

	// 生长曲线
	UPROPERTY(EditDefaultsOnly, DisplayName="生长曲线", Category="默认|生长相关")
	TObjectPtr<UCurveFloat> GrowthCurve;

	// 生长的时间
	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(ExposeOnSpawn = "true"), DisplayName="生长的时间", Category="默认|生长相关")
	float GrowthTime = 1.f;

	// 缩放曲线
	UPROPERTY(EditDefaultsOnly, meta=(EditCondition = "bCanScale == true", EditConditionHides), DisplayName="缩放曲线", Category="默认|生长相关")
	TObjectPtr<UCurveFloat> ScaleCurve;

	// Q弹时间
	UPROPERTY(BlueprintReadWrite, EditAnywhere, meta=(EditCondition = "bCanScale == true", EditConditionHides, ExposeOnSpawn = "true"), DisplayName="Q弹时间", Category="默认|生长相关")
	float ScaleTime = 0.5f;

	// Q弹大小
	UPROPERTY(BlueprintReadWrite, EditAnywhere, meta=(EditCondition = "bCanScale == true", EditConditionHides, ExposeOnSpawn = "true"), DisplayName="Q弹的大小比例", Category="默认|生长相关")
	FVector ScaleSize = FVector(1.f, 1.f, 1.f);

	// 枯萎(或恢复生机的曲线)
	UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, DisplayName="枯萎(或恢复生机的曲线)", Category="默认|生长相关")
	TObjectPtr<UCurveFloat> WitheredCurve;

	// 枯萎或恢复生机的时间
	UPROPERTY(BlueprintReadWrite, EditAnywhere, meta=(ExposeOnSpawn = "true"), DisplayName="枯萎或恢复生机的时间", Category="默认|生长相关")
	float WitheredTime = 1.f;

protected:
	virtual void BeginPlay() override;

	virtual void OnConstruction(const FTransform& Transform) override;

	// 初始化
	void Init();

	UPROPERTY(VisibleDefaultsOnly, Category="组件")
	TObjectPtr<UBoxComponent> Box;

	// 植物的组件
	UPROPERTY(EditDefaultsOnly, Category="组件")
	TObjectPtr<USkeletalMeshComponent> PlantMesh;

	// 植物的骨骼网格体
	UPROPERTY(EditAnywhere, meta=(ExposeOnSpawn = "true"), BlueprintReadWrite, DisplayName="植物网格体", Category="默认")
	TObjectPtr<USkeletalMesh> PlantMeshAsset;

	// 枯萎动画
	UPROPERTY(EditAnywhere, BlueprintReadWrite, DisplayName="枯萎动画", Category="默认")
	TObjectPtr<UAnimationAsset> WitheredAnim;

	// 茂盛动画
	UPROPERTY(EditAnywhere, BlueprintReadWrite, DisplayName="茂盛动画", Category="默认")
	TObjectPtr<UAnimationAsset> RevitalizeAnim;

	// Box开始重叠
	/*UFUNCTION()
	void BoxBeginOverlap(
		UPrimitiveComponent* OverlappedComp,
		AActor* OtherActor,
		UPrimitiveComponent* OtherComp,
		int32 OtherBodyIndex,
		bool bFromSweep,
		const FHitResult& SweepResult);*/

	// 生长时间轴
	UPROPERTY()
	TObjectPtr<UTimelineComponent> GrowthTimeLine;

	//更新时间轴图表的浮点轨道 -- 这个是生长的
	UPROPERTY()
	FOnTimelineFloat GrowthUpdateFloat;

	//更新生长时间轴的事件
	UFUNCTION()
	void UpdateTimelineCompGrowth(const float Output);

	//生长时间轴完成事件
	UPROPERTY()
	FOnTimelineEvent GrowthOnFinishFunction;

	//生长时间轴播放完成
	UFUNCTION()
	void GrowthOnFinish();

	// 缩放的时间轴
	UPROPERTY()
	TObjectPtr<UTimelineComponent> ScaleTimeLine;

	//更新时间轴图表的浮点轨道 -- 这个是缩放的Q弹效果
	UPROPERTY()
	FOnTimelineFloat ScaleUpdateFloat;

	//更新生长时间轴的事件
	UFUNCTION()
	void UpdateTimelineCompScale(const float Output);

	//生长时间轴完成事件
	UPROPERTY()
	FOnTimelineEvent ScaleOnFinishFunction;

	//生长时间轴播放完成
	UFUNCTION()
	void ScaleOnFinish();

	// 枯萎，恢复生机的时间轴
	UPROPERTY()
	TObjectPtr<UTimelineComponent> WitheredTimeLine;

	//更新时间轴图表的浮点轨道 --
	UPROPERTY()
	FOnTimelineFloat WitheredUpdateFloat;

	//更新枯萎(或恢复生机)时间轴的事件
	UFUNCTION()
	void UpdateTimelineCompWithered(const float Output);

	//枯萎(或恢复生机)时间轴完成事件
	UPROPERTY()
	FOnTimelineEvent WitheredOnFinishFunction;

	//枯萎(或恢复生机)时间轴播放完成
	UFUNCTION()
	void WitheredOnFinish();

	// 所以模型组件
	UPROPERTY()
	TArray<UMeshComponent*> AllMeshComponent;

	// 获取所以模型组件
	void GetAllMeshComponent();

public:
	// 重写触发重叠生长
	UFUNCTION(BlueprintCallable, CallInEditor, DisplayName="生长", Category="交互函数")
	virtual void TriggerOverlapGrowth() override;

	// 重写触发重叠枯萎
	UFUNCTION(BlueprintCallable, CallInEditor, DisplayName="枯萎", Category="交互函数")
	virtual void TriggerOverlapWithered() override;

	// 重写触发重叠茂盛
	UFUNCTION(BlueprintCallable, CallInEditor, DisplayName="茂盛", Category="交互函数")
	virtual void TriggerOverlapRevitalize() override;

	// 可以重叠
	uint8 bCanOverlap : 1;

	// 可以Q弹
	UPROPERTY(EditAnywhere, meta=(ExposeOnSpawn = "true"), BlueprintReadWrite, DisplayName="可以Q弹", Category="默认|生长相关")
	uint8 bCanScale : 1;

	// 在枯萎(或恢复生机)
	uint8 bInWithered : 1;
};
